#include "../include/test.h"
#include "../include/vfs_errorcodes.h"
#include<stdio.h>
#include<string.h>
#include "../include/Hash.h"
#include<stdlib.h>
#include "../include/bst.h"
#include "../include/linked_block.h"
void writeDataBlocks(char *data,int block_number,int);
int makedir(char * path,char * dir_name);
int hasInvalidCharacterInName(char * string);

FILE *fp;
Free_Block * block_head;

char * create_file_system(char *label,int size)
{


  int i,j;

  FILE * fp1;
  FILE * fp2;

  if(size <1 || size >1024)
  {

   strcpy(error,"createvfs_FAILURE ");
   strcat(error,ERR_VFS_CREATE_04);
   return error;
  }

   if(strlen(label) > 30)
   {
        strcpy(error,"createvfs_FAILURE ");
        strcat(error,ERR_VFS_CREATE_05);
   	return error;

   }

   if(hasInvalidCharacterInName(label))
   {
       strcpy(error,"createvfs_FAILURE ");
        strcat(error,ERR_VFS_CREATE_03);
   	return error;

   }

  if((fp1=fopen(label,"r"))!=NULL)
  {
   strcpy(error,"createvfs_FAILURE ");
   strcat(error,ERR_VFS_CREATE_01);
   return error;
  }

  //fclose(fp1);


  if((fp2=fopen(label,"wb+"))==NULL)
  {
   strcpy(error,"createvfs_FAILURE ");
   strcat(error,ERR_VFS_CREATE_02);
   return error;
  }
  else
  {
    struct MainHeader md;
    strcpy(md.FILE_SYSTEM_LABEL,label);
    md.MAX_FILE_DESCRIPTORS=MAX_NO_OF_FD;
    md.used_File_Descriptors=1;
    //initialize all free blocks as 0-stands for free
    Total_No_Of_Blocks = size;
    for(j=0;j<Total_No_Of_Blocks;j++)
    {
      md.free_blocks[j]=0;
    }
    strcpy(md.fd[0].file_name,"/");
    strcpy(md.fd[0].path,"/");
    strcpy(md.fd[0].location_path,"0");
    md.fd[0].file_descriptor_no=0;
    md.fd[0].parent_file_descriptor_no=0;
    md.fd[0].used_flag=1;
    md.size=Total_No_Of_Blocks;
    //initialize all file descriptors(except 0) as unsused-0

   for(j=1;j<MAX_NO_OF_FD;j++)
     {
         md.fd[j].used_flag=0;

     }
    fwrite(&md,sizeof(struct MainHeader),1,fp2);


    struct block b;
    //Write all empty blocks into the file
    for(i=0;i<Total_No_Of_Blocks;i++)
    {

     b.block_number = i;
     fwrite(&b,sizeof(struct block),1,fp2);

    }
   fclose(fp2);
  // printf("\ncreatevfs_SUCCESS\n");
   strcpy(error,"createvfs_SUCCESS");
  }


 return error;




}


char * mount(char *label)
{
 int i,j,count=0;
 char s[50],ch;
  if((fp=fopen(label,"rb+"))==NULL)
  {
    strcpy(error,"mountvfs_FAILURE ");
    strcat(error,ERR_VFS_MOUNT_01);
   // printf("Filesystem with name %s is not created",label);
    return error;
  }

  else
  {
    	//Read the header
       if((fread(&header,sizeof(struct MainHeader),1,fp))==0) {
        strcpy(error,"mountvfs_FAILURE ");
        strcat(error,ERR_VFS_MOUNT_02);

       return error;
       }

        for(j=0;j<MAX_NO_OF_FD;j++)
        {
           if(header.fd[j].used_flag==1)
            {
              //Form the headers into n-ary tree

              addNode(header.fd[j].file_descriptor_no);
              //traverse(vfs);
              //Add the file descriptors into hash table

              add_to_hash_table(header.fd[j].path,j);
            }


        }

// populate free block list

  for(j=0;j<header.size;j++)
  {
	if(header.free_blocks[j]==0)
	{
          block_head=add_free_block(block_head,j);
          count++;
        }

  }





  strcpy(error,"mountvfs_SUCCESS");
 // printf("\nFilesystem successfully mounted\n");

}





 return error;


}

//unmount the filesystem
char * unmount(char * label)
{

       rewind(fp);
       int i;

       if(strcmp(header.FILE_SYSTEM_LABEL,label)!=0)
        {
		 strcpy(error,"unmountvfs_FAILURE ");
           	 strcat(error,ERR_VFS_UNMOUNT_01);
                 return error;
        }
        int count=0;


        //put the free block list back to header
       for(i=0;i<header.size;i++)
	{

          if(search_blocks(i,block_head))
	  {
		header.free_blocks[i]=0;
                 count++;
          }
	  else
		header.free_blocks[i]=1;


	}


        //write the header back to the file.
        if((fwrite(&header,sizeof(struct MainHeader),1,fp))==0) {
           strcpy(error,"unmountvfs_FAILURE ");
           strcat(error,ERR_VFS_UNMOUNT_02);
        }

        else {
        fclose(fp);
        strcpy(error,"unmountvfs_SUCCESS");

        }
	vfs=NULL;
	bst=NULL;
	for(i=0;i<HASH_SIZE;i++){
		hashtABLE[i]=NULL;
	}
        block_head=NULL;   
        return error;
}

int findParentDesc(char *path){


	return search_from_hash_table(path);
}


//Check whether the path is valid one
int isValidPath(char *path){
	if(search_from_hash_table(path)!=-1)
	 return 1;
        else
         return 0;
}
//create directory
char * create_rec_dir(char *path,char *dir_name)
{

  char *temppath,*dirpath;
  temppath=(char *)malloc(strlen(path)*sizeof(char));
  dirpath = (char *)malloc(strlen(path)*sizeof(char)+1);

  strcpy(temppath,path);
  int j=0,i=0,k=0;
  int error_flag=0;
  if(path[0]!='/')
  {
      strcpy(error,"makedir_FAILURE ");
      strcat(error, ERR_VFS_MAKEDIR_05);
      return error;
    

  }
    

  if(hasInvalidCharacterInName(dir_name))
   {
       strcpy(error,"makedir_FAILURE ");
        strcat(error,ERR_VFS_MAKEDIR_02);
   	return error;

   }

  if(!isValidPath(path))
  {

   while(!isValidPath(temppath))
   {
       j=strlen(temppath)-1;

	while(temppath[j]!='/')
         j--;
	if(j!=0)
       temppath[j]='\0';
       else
	temppath[1]='\0';



   }




 j=strlen(temppath);
 if(j==1)
  strcpy(dirpath,path);
 else
   strcpy(dirpath,path+j);
 strcat(dirpath,"/");


 char dir[50];
 j=0;

 for(i=1;i<strlen(dirpath);i++)
 {
   if(dirpath[i]=='/')
   {

     dir[j]='\0';
     j=0;


     error_flag=makedir(temppath,dir);
     if(error_flag)
       return error;
     if(strlen(temppath)>1)
       strcat(temppath,"/");

     strcat(temppath,dir);

   }

   else
   {
     dir[j++]=dirpath[i];


   }


 }

}
error_flag=makedir(path,dir_name);
if(!error_flag)
 {

   strcpy(error,"makedir_SUCCESS");

 }


return error;

//free(dpath);
}





//Create a directory
int makedir(char * path,char * dir_name){
	int index=0,j=0,i=0;
         char new_path[100];

        if(header.used_File_Descriptors>=MAX_NO_OF_FD)
        {

            	  strcpy(error,"makedir_FAILURE ");
		  strcat(error,ERR_VFS_MAKEDIR_01);
                  return 1;
        }
	if(isValidPath(path)){



                while(path[i]!='\0')
                  new_path[j++]=path[i++];
                if(strlen(path)>1)
                 new_path[j++]='/';
                i=0;
                 while(dir_name[i]!='\0')
                  new_path[j++]=dir_name[i++];
                 new_path[j]='\0';

                if(search_from_hash_table(new_path)!=-1)
                {
		  strcpy(error,"makedir_FAILURE ");
		  strcat(error,ERR_VFS_MAKEDIR_03);
                 // printf(ERR_VFS_MAKEDIR_03);
                  return 1;

                }
                else;
                {
		while(header.fd[index].used_flag == 1)
			index++;

		header.fd[index].file_descriptor_no = index;
		header.fd[index].parent_file_descriptor_no= findParentDesc(path);//change it to the parent file descriptor no

		sprintf(header.fd[index].file_name,"%s",dir_name);//change the file name size
		sprintf(header.fd[index].location_path,"%s/%d",header.fd[header.fd[index].parent_file_descriptor_no].location_path,index);//change the location path size
		header.fd[index].file_type = 'd';
		header.fd[index].file_size = 0;
		header.fd[index].location_block_number = -1; // SHOULD CAHNGE
                header.fd[index].used_flag=1;

                addNode(header.fd[index].file_descriptor_no);

	        add_to_hash_table(new_path,index);
		strcpy(header.fd[index].path,new_path);
                header.used_File_Descriptors++;
               // printf("\nmakedir_SUCCESS\n");

                }
	}
        else
        {


         //  printf(ERR_VFS_MAKEDIR_01);

           return 1;
        }

   return 0;

}

int  fetch_data_from_file(char * data_file_path,int file_descriptor_no,char mode)
{

  FILE *fp2;
  char ch;
  char * data;
  int i=0,j=0,blockindex=0,j1=0,count=0,k;
  
  if((fp2=fopen(data_file_path,"rb"))==NULL)   //////////////// CHANGED HERE
  {
   
    if(mode=='c')
    {
    	strcpy(error,"addfile_FAILURE ");
    	strcat(error,ERR_VFS_ADDFILE_05);
    }
    else
    {
         strcpy(error,"updatefile_FAILURE ");
    	strcat(error,ERR_VFS_UPDATEFILE_02);

    }
    return -1;
  }

  fseek(fp2, 0L, SEEK_END);
  int sz = ftell(fp2);
  
  rewind(fp2);

 

  count=countFreeBlocks(block_head);

   
  if(sz >=50*1024 || (sz/1024 +1)> count)
  {
    if(mode=='c')
    {
    strcpy(error,"addfile_FAILURE ");
    strcat(error,ERR_VFS_ADDFILE_06);
    }
    else
    {

      strcpy(error,"updatefile_FAILURE ");
      strcat(error,ERR_VFS_UPDATEFILE_03);
   }


    return -1;


 }
  else
  {
    data=malloc(sizeof(char)*1024);
    
    header.fd[file_descriptor_no].file_size = 0;
     while(!feof(fp2))
      {
      	 fread(data+i,sizeof(char),1,fp2);
         i=i+1;
         if(i==1024)
         {
         	blockindex = get_free_block(&block_head);
                if(blockindex==-1)
		{

			strcpy(error,"addfile_FAILURE ");
    			strcat(error,ERR_VFS_ADDFILE_04);
			return -1;

		}

			writeDataBlocks(data,blockindex,i);
			header.fd[file_descriptor_no].block_numbers[j++]=blockindex;
			//header.free_blocks[blockindex]=1;
			header.fd[file_descriptor_no].file_size +=1024 ;
			i=0;

         }

      }
      i--;
      blockindex = get_free_block(&block_head);
	  writeDataBlocks(data,blockindex,i);
      header.fd[file_descriptor_no].block_numbers[j++]=blockindex;
      header.free_blocks[blockindex]=1;
      header.fd[file_descriptor_no].block_numbers[j++]=-1;
	  header.fd[file_descriptor_no].file_size += i;

  }

}

//create filedescriptor for the new file
char * create(char * path,char * file_name,char * data_file_path)
{
	int index=0,j=0,i=0,blockindex=0,k=0;
        char new_path[200];
        char * data;
       
       if(hasInvalidCharacterInName(file_name))
   {
       strcpy(error,"createvfs_FAILURE ");
        strcat(error,ERR_VFS_ADDFILE_02);
   	return error;

   }

   
       
        
	if(isValidPath(path)){

	        while(path[i]!='\0')
                  new_path[j++]=path[i++];
                if(strlen(path)>1)
                 new_path[j++]='/';
                 i=0;
                 while(file_name[i]!='\0')
                  new_path[j++]=file_name[i++];
                 new_path[j]='\0';


                //Check if file already exists
                

                if(search_from_hash_table(new_path)!=-1)
                {
                  // 	printf("\nFile already exists in this location\n");
			strcpy(error,"addfile_FAILURE ");
		  	strcat(error,ERR_VFS_ADDFILE_03);
     		  	return error;


                }


              else
              {

                if(index>=MAX_NO_OF_FD)
		{
		  	//printf("\nFile already exists in this location\n");
			strcpy(error,"addfile_FAILURE ");
		  	strcat(error,ERR_VFS_ADDFILE_04);
     		  	return error;

                }
	
		while(header.fd[index].used_flag == 1)
			index++;
               
                if(fetch_data_from_file(data_file_path,index,'c')==-1)
                    return error;
                 
		header.fd[index].file_descriptor_no = index;
                header.fd[index].parent_file_descriptor_no = findParentDesc(path);
                
		//change it to the parent file descriptor no
		sprintf(header.fd[index].file_name,"%s",file_name);//change the file name size
		sprintf(header.fd[index].location_path,"%s/%d",header.fd[header.fd[index].parent_file_descriptor_no].location_path,index);
		header.fd[index].file_type = 'f';
                

                header.fd[index].used_flag=1;

                addNode(header.fd[index].file_descriptor_no);
                add_to_hash_table(new_path,index);
		strcpy(header.fd[index].path,new_path);
		header.used_File_Descriptors++;

                bst=insert_bst(file_name,bst,index);


		strcpy(error,"addfile_SUCCESS ");
             }
	}
         else
        {

           	  strcpy(error,"addfile_FAILURE ");
		  strcat(error,ERR_VFS_ADDFILE_01);

        }

  return error;
}

//write to the data block in the file

void writeDataBlocks(char *data,int block_number,int size)
{

       int i=0;
       rewind(fp);
       //seek the file pointer to the end of header
       fseek(fp,sizeof(struct MainHeader),SEEK_CUR);
       //seek to the block number
       fseek(fp, block_number*(sizeof(struct block)), SEEK_CUR);
       struct block b;
       fread(&b,sizeof(struct block),1,fp);
       //strcpy(b.fixed_size_buffer,data);
       while(i<=size){
       	b.fixed_size_buffer[i]=data[i];
       	i++;
       	}
       fseek(fp, -(sizeof(struct block)), SEEK_CUR);
       fwrite(&b,sizeof(struct block),1,fp);


}

int  put_data_into_file(char * file_path,char * data)
{
 FILE * fp2;
 int i=0;
  if((fp2=fopen(file_path,"ab+"))==NULL)  //////////////// CHANGED HERE
  {
  // printf("\nDestination path not found\n");
   return 0;
  }
 else
 {


   	fwrite(data,1024,1,fp2);

 }

 fclose(fp2);
 return 1;
}
//update file contents by another file

char * update_file_contents(char *path,char * data_file_path)
{

  int file_descriptor_no;
  char * data;
  int i=0;
  if(isValidPath(path)){




                file_descriptor_no = findParentDesc(path);

                while(header.fd[file_descriptor_no].block_numbers[i]!=-1)
                	{
                	   block_head=add_free_block(block_head,header.fd[file_descriptor_no].block_numbers[i]);
                	   //header.free_blocks[header.fd[file_descriptor_no].block_numbers[i]]=0;
                	   i++;
                	}

                 header.fd[file_descriptor_no].block_numbers[0]=-1;
                 fetch_data_from_file(data_file_path,file_descriptor_no,'u');

       //writeDataBlocks(data,fp,block_number);
        strcpy(error,"update_SUCCESS ");

  }
   else
   {

       strcpy(error,"update_FAILURE ");
		  strcat(error,ERR_VFS_UPDATEFILE_01);


   }

  return error;

}




//List file contents to another file
char * list_File(char *path,char * dest_file_path,char mode)
{

  int file_descriptor_no;
  int i=0;
  FILE * fp2;

  if(isValidPath(path)){

 file_descriptor_no = findParentDesc(path);

	 if(mode =='l' && strstr(header.fd[file_descriptor_no].file_name,".txt")==NULL)
	 {

		strcpy(error,"listfile_FAILURE ");
		strcat(error,ERR_VFS_LISTFILE_02);
		return error;

	}

        if(mode == 'e' && header.fd[file_descriptor_no].file_type=='d')
	{
		
                strcpy(error,"exportfile_FAILURE ");
 		strcat(error,ERR_VFS_EXPORTFILE_03);
                return error;
	}


         // int block_number[]=header.fd[file_descriptor_no].block_numbers;
         if((fp2=fopen(dest_file_path,"wb+"))==NULL)  //////////////// CHANGED HERE
  		{
   		//	printf("\nDestination path not found\n");
                        if(mode=='l')
			{
				strcpy(error,"listfile_FAILURE ");
		  		strcat(error,ERR_VFS_LISTFILE_03);
			}
			else
			{
				strcpy(error,"exportfile_FAILURE ");
		  		strcat(error,ERR_VFS_EXPORTFILE_02);
			}

   			return error;
 		 }

		else{
         	while(header.fd[file_descriptor_no].block_numbers[i] != -1){
	     	  rewind(fp);
		       //seek the file pointer to the end of header
		       fseek(fp,sizeof(struct MainHeader),SEEK_CUR);
		       //seek to the block number
		       fseek(fp, header.fd[file_descriptor_no].block_numbers[i]*(sizeof(struct block)), SEEK_CUR);
		       struct block b;
		       fread(&b,sizeof(struct block),1,fp);
		       int curSize = header.fd[file_descriptor_no].file_size;
		      // fwrite(b.fixed_size_buffer,1024,1,fp2);
		    	if(header.fd[file_descriptor_no].block_numbers[i+1] == -1){
		    		if(curSize%1024 == 0)
				   		fwrite(b.fixed_size_buffer,1024,1,fp2);
				   	else
				   		fwrite(b.fixed_size_buffer,curSize%1024,1,fp2);
				}else{
			   		fwrite(b.fixed_size_buffer,1024,1,fp2);
				}
				i++;
 			}
	    }
	     fclose(fp2);

       strcpy(error,"listfile_SUCCESS ");


  }
   else
   {
			if(mode=='l')
			{

      				strcpy(error,"listfile_FAILURE ");
		  		strcat(error,ERR_VFS_LISTFILE_01);
			}
     		  	else
			{
				strcpy(error,"exportfile_FAILURE ");
		  		strcat(error,ERR_VFS_EXPORTFILE_02);
			}

   }


  return error;
}

char * move_dir(char * oldpath,char * newpath,char type)
{

    int fdnum_old=search_from_hash_table(oldpath);


    if(fdnum_old==-1 || fdnum_old==0)
    {

       if(type=='d')
       {
       		strcpy(error,"movedir_FAILURE ");
       		strcat(error,ERR_VFS_MOVEDIR_01);
	}
        else
	{
		strcpy(error,"movefile_FAILURE ");
       		strcat(error,ERR_VFS_MOVEFILE_01);
        }
      // 	printf("Source directory does not exist");
       return error;

    }

   else
   {
     if(type=='d' && header.fd[fdnum_old].file_type=='f')
     {

        strcpy(error,"movedir_FAILURE ");
        strcat(error,ERR_VFS_MOVEDIR_04);
	return error;
     }

    // return error;
   }

    int fdnum_new_path=search_from_hash_table(newpath);
    if(header.fd[fdnum_old].parent_file_descriptor_no==fdnum_new_path)
    {
      	strcpy(error,"movedir_FAILURE ");
        strcat(error,ERR_VFS_MOVEDIR_06);
	return error;

    }


    if(fdnum_new_path==-1)
    {

      if(type=='d')
      {
     	 strcpy(error,"movedir_FAILURE ");
      	 strcat(error,ERR_VFS_MOVEDIR_02);
      }
      else
      {
	 strcpy(error,"movefile_FAILURE ");
       	 strcat(error,ERR_VFS_MOVEFILE_02);

      }
    //  printf("Destination directory does not exist");
      return error;
    }

    if(header.fd[fdnum_new_path].file_type=='f')
    {

        if(type=='d')
      {
     	 strcpy(error,"movedir_FAILURE ");
      	 strcat(error,ERR_VFS_MOVEDIR_07);
      }

    //  printf("Destination path cannot be a file");
      return error;


    }
	//printf("I am about to give error\n");
	if((strncmp(oldpath,newpath,strlen(oldpath))==0)&&((newpath[strlen(oldpath)]=='/')||(strlen(oldpath)==strlen(newpath)))){
		//printf("I am in if condition\n");
		strcpy(error,"movedir_FAILURE ");
		strcat(error,ERR_VFS_MOVEDIR_06);
		return error;
	}

    char * temppath;
    temppath = (char *)malloc(strlen(newpath)+strlen(header.fd[fdnum_old].file_name)+2);
    sprintf(temppath,"%s/%s",newpath,header.fd[fdnum_old].file_name);
    if(search_from_hash_table(temppath)!=-1)
    {
	 if(type=='d')
      	 {
	 strcpy(error,"movedir_FAILURE ");
         strcat(error,ERR_VFS_MOVEDIR_05);
	 }

      	//	printf("Destination directory already has src directory");
        return error;

    }

   moveNode(fdnum_old,fdnum_new_path);
   if(type=='d')
   {
  	strcpy(error,"movedir_SUCCESS ");
   }
   else
   {
	strcpy(error,"movefile_SUCCESS ");
   }
  return error;
}

char * movefile(char *srcfilepath,char *destfilepath)
{

 int srcfd=search_from_hash_table(srcfilepath);
 char * dirpath=(char *)malloc(sizeof(char)*strlen(destfilepath));
 char file_name[100];
 if(srcfd==-1 || header.fd[srcfd].file_type=='d')
 {

   strcpy(error,"movefile_FAILURE ");
   strcat(error,ERR_VFS_MOVEFILE_01);
   return error;
 }



 int destfd=search_from_hash_table(destfilepath);
  
 if(destfd!=-1 && header.fd[destfd].file_type=='d')
 {
   
   strcpy(error,"movefile_FAILURE "); 
   strcat(error,ERR_VFS_MOVEFILE_02);
   return error;

 }
 if(destfd!=-1)
 {
   removedir(destfilepath,'f');

 }
else
{
  int i=strlen(destfilepath)-1;
  while(destfilepath[i--]!='/');
  strncpy(dirpath,destfilepath,i+1);
  strcpy(file_name,destfilepath+i+2);
  
  destfd=search_from_hash_table(dirpath);
  if(destfd==-1)
  {
    strcpy(error,"movefile_FAILURE ");
   strcat(error,ERR_VFS_MOVEFILE_02);
   return error;

  }

  strcpy(header.fd[srcfd].file_name,file_name);
  
  reHash(srcfd);
  if(header.fd[srcfd].parent_file_descriptor_no!=destfd)
  	moveNode(srcfd,destfd);
  
  
  strcpy(error,"movefile_SUCCESS ");
  free(dirpath);
  return error;
}





}





char * removedir(char * path,char type)
{

  int fd=search_from_hash_table(path);
  if(fd==-1 || fd==0)
  {

   if(type=='d')
   {
    strcpy(error,"deletedir_FAILURE ");
    strcat(error,ERR_VFS_DELETEDIR_01);
   }
   else
   {
     strcpy(error,"removefile_FAILURE ");
    strcat(error,ERR_VFS_REMOVEFILE_01);
   }
   // printf("\nPath is not valid\n");
    return error;
  }
  else
  {

    if(type!='d' && header.fd[fd].file_type=='d')
    {

      strcpy(error,"removefile_FAILURE ");
      strcat(error,ERR_VFS_REMOVEFILE_01);

    }
    if(removeNode(fd)==-1)
    {
      strcpy(error,"deletedir_FAILURE ");
    strcat(error,ERR_VFS_DELETEDIR_02);
    return error;
    }

  }


 if(type=='d')
 	strcpy(error,"deletedir_SUCCESS ");
 else
 {

    strcpy(error,"removefile_SUCCESS ");
    int i=0;
    //=block_head=add_free_block(block_head,header.fd[fd].location_block_number);
    while(header.fd[fd].block_numbers[i]!=-1)
                	{
                	   block_head=add_free_block(block_head,header.fd[fd].block_numbers[i]);
                	   //header.free_blocks[header.fd[fd].block_numbers[i]]=0;
                	   i++;
                	}

                 header.fd[fd].block_numbers[0]=-1;
 }
 return error;

}

char * copy(char *src_path,char *dest_path)
{

   int fd1=search_from_hash_table(src_path);
   if(fd1==-1)
   {
     strcpy(error,"copyfile_FAILURE ");
     strcat(error,ERR_VFS_COPYFILE_01);
     return error;

   }

   int fd2=search_from_hash_table(dest_path);
   if(fd2==-1 || header.fd[fd2].file_type=='d')
   {
     strcpy(error,"copyfile_FAILURE ");
     strcat(error,ERR_VFS_COPYFILE_02);

     return error;


   }

   if(header.fd[fd1].file_type=='d')
   {

     strcpy(error,"copyfile_FAILURE ");
     strcat(error,ERR_VFS_COPYFILE_03);

     return error;

   }



   //LISTFILE src path;
   list_File(src_path,"temp",'e');

   update_file_contents(dest_path,"temp");
   remove("temp");

   strcpy(error,"copyfile_SUCCESS ");


   return error;


  //Used file descriptor should be increased



}

int hasInvalidCharacterInName(char * string)
{

  if(strstr(string,"/")!=NULL)
    return 1;

  return 0;

}




